﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using SerialozLibrary;

namespace SSS.AlphaNN.Components
{
    public class Link
    {
        #region Fields

        private bool marked = false;

        #endregion

        #region Properties
        /// <summary>
        /// 
        /// </summary>
        public Slot Slot1
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public Slot Slot2
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public Color LinkColor
        {
            get;
            set;
        }
        
        /// <summary>
        /// 
        /// </summary>
        public bool Mark
        {
            set
            {
                LinkColor = (marked = value) ? Color.Orange : Color.FromArgb(128, Color.Orange);
            }
            get
            {
                return marked;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public double ValueLink
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        public Dummy componentSlot1
        {
            get
            {
                return Slot1.Owner;
            }
            set
            {
                Slot1.Owner = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Dummy componentSlot2
        {
            get
            {
                return Slot2.Owner;
            }
            set
            {
                Slot2.Owner = value;
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int IdentificatorComponentSlot1
        {
            get
            {
                return Slot1.Owner.Identificator;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public int IdentificatorComponentSlot2
        {
            get
            {
                return Slot2.Owner.Identificator;
            }
        }


        #endregion

        /// <summary>
        /// 
        /// </summary>
        /// <param name="slot1"></param>
        /// <param name="slot2"></param>
        public Link( Slot slot1, Slot slot2 )
        {
            this.Slot1 = slot1;
            this.Slot2 = slot2;
            LinkColor = Color.FromArgb( 128, Color.Orange );
        }

        public LinkGhost GetGhost()
        {
            LinkGhost lg = new LinkGhost();
            lg.slot1_name = new StringBuilder( this.Slot1.Name );
            lg.slot2_name = new StringBuilder( this.Slot2.Name );
            lg.dummy1_id = ( Slot1.Owner as Dummy ).Identificator;
            lg.dummy2_id = ( Slot2.Owner as Dummy ).Identificator;
            lg.value=this.ValueLink;
            return lg;
        }

    }
}
